package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class NewsPage extends BaseDomain{

    private String title;

    private String subTitle;

    private String author;

    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;

    private String coverUrl;

    private Integer state;

    private NewsContent newsContent;

    public static final Integer STATE_WAIT = 1; //发布
    public static final Integer STATE_RELEASE = 2; //禁用

    public String getStateName(){
        String msg = "已发布";
        if (state == STATE_RELEASE){
            msg = "禁用";
        }
        return msg;
    }

    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("subTitle",subTitle);
        map.put("coverUrl",coverUrl);
        map.put("state",state);
        return JSONUtil.toJSONString(map);
    }



}